package com.ruoyi.internet.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.internet.domain.IntNotice;
import com.ruoyi.internet.service.IIntNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 资讯公告Controller
 *
 * @author cjie
 * @date 2021-08-16
 */
@Api(tags = " 资讯公告")
@RestController
@RequestMapping("/intNotice")
public class IntNoticeController extends BaseController {
    @Autowired
    private IIntNoticeService intNoticeService;

    /**
     * 查询资讯公告列表
     */
    @ApiOperation(value="查询资讯公告列表", notes="查询资讯公告列表")
    @PreAuthorize(hasPermi = "internet:intNotice:list")
    @GetMapping("/list")
    public TableDataInfo list(IntNotice intNotice) {
        startPage();
        List<IntNotice> list = intNoticeService.selectIntNoticeList(intNotice);
        return getDataTable(list);
    }

    /**
     * 导出资讯公告列表
     */
    @ApiOperation(value="导出资讯公告列表", notes="导出资讯公告列表")
    @PreAuthorize(hasPermi = "internet:intNotice:export")
    @Log(title = "资讯公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntNotice intNotice) throws IOException {
        List<IntNotice> list = intNoticeService.selectIntNoticeList(intNotice);
        ExcelUtil<IntNotice> util = new ExcelUtil<IntNotice>(IntNotice.class);
        util.exportExcel(response, list, "资讯公告数据");
    }
    /**
     * 获取资讯公告详细信息
     */
    @ApiOperation(value="获取资讯公告详细信息", notes="获取资讯公告详细信息")
    @PreAuthorize(hasPermi = "internet:intNotice:query")
    @GetMapping(value = "/info/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Integer noticeId) {
        return AjaxResult.success(intNoticeService.selectIntNoticeById(noticeId));
    }

    /**
     * 新增资讯公告
     */
    @ApiOperation(value="新增资讯公告", notes="新增资讯公告")
    @PreAuthorize(hasPermi = "internet:intNotice:add")
    @Log(title = "资讯公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntNotice intNotice) {
        return toAjax(intNoticeService.insertIntNotice(intNotice));
    }

    /**
     * 修改资讯公告
     */
    @ApiOperation(value="修改资讯公告", notes="修改资讯公告")
    @Log(title = "资讯公告", businessType = BusinessType.UPDATE)
    @PreAuthorize(hasPermi = "internet:intNotice:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody IntNotice intNotice) {
        return toAjax(intNoticeService.updateIntNotice(intNotice));
    }

    /**
     * 删除资讯公告
     */
    @ApiOperation(value="删除资讯公告", notes="删除资讯公告")
    @ApiImplicitParam(name = "ids", value = "资讯公告ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @Log(title = "资讯公告", businessType = BusinessType.DELETE)
    @PreAuthorize(hasPermi = "internet:intNotice:remove")
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Integer[] noticeIds) {
        return toAjax(intNoticeService.deleteIntNoticeByIds(noticeIds));
    }
}
